#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int N=1e6+50;
const int M=1e7+50;
const int INF=0x3f3f3f3f;
struct Edge{
    int to,cap,flow,cost,next;
}edge[M];
int tot;
int head[N];
int pre[N],dis[N];
bool vis[N];
int Nx;
void init(int n){
    Nx=n;
    tot=0;
    memset(head,-1,sizeof(head));
}
void addEdge(int u,int v,int cap,int cost){
    edge[tot]=Edge{v,cap,0,cost,head[u]};
    head[u]=tot++;
    edge[tot]=Edge{u,0,0,-cost,head[v]};
    head[v]=tot++;
}
bool spfa(int s,int t){
    queue<int> q;
    for(int i=0;i<Nx;i++){
        dis[i]=INF;
        vis[i]=false;
        pre[i]=-1;
    }
    vis[s]=true;
    dis[s]=0;
    q.push(s);
    while(!q.empty()){
        int u=q.front();
        q.pop();
        vis[u]=false;
        for(int i=head[u];i!=-1;i=edge[i].next){
            int v=edge[i].to;
            if(edge[i].cap>edge[i].flow && dis[v]>dis[u]+edge[i].cost){
                dis[v]=dis[u]+edge[i].cost;
                pre[v]=i;
                if(!vis[v]){
                    vis[v]=true;
                    q.push(v);
                }
            }
        }
    }
    return pre[t]!=-1;
}
int mcmf(int s,int t,int &cost){
    int flow=0;
    cost=0;
    while(spfa(s,t)){
        int Min=INF;
        for(int i=pre[i];i!=-1;i=pre[edge[i^1].to]){
            if(Min>edge[i].cap-edge[i].flow){
                Min=edge[i].cap-edge[i].flow;
            }
        }
        for(int i=pre[t];i!=-1;i=pre[edge[i].to]){
            edge[i].flow+=Min;
            edge[i^1].flow-=Min;
            cost+=edge[i].cost*Min;
        }
        flow+=Min;
    }
    return flow;
}
int main(void){
    return 0;
}